//
//  MYUpDownBtn.m
//  HZTC_YaDeArt
//
//  Created by MayerF on 17/4/7.
//  Copyright © 2017年 HZTC. All rights reserved.
//

#import "MYUpDownBtn.h"

@implementation MYUpDownBtn

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    [super setImage:image forState:state];
    
    if (self.imageView.image) {
        // 图片保持原状居中
        self.imageView.contentMode = UIViewContentModeCenter;
        // 文字居中
        //        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        // 设置字体
        //        self.titleLabel.font = [UIFont systemFontOfSize:13];
    }else{
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
}

/**
 *  内部图片（上下格式）
 */
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    if (!self.currentTitle) {
        return [super imageRectForContentRect:contentRect];
    }
    if (contentRect.size.height < 60) {
        contentRect.size.height = 60;
    }
    // 设置属性
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height - 20;
    
    return CGRectMake(0, 0, imageW, imageH);
}
/**
 *  内部文字
 */
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    if (contentRect.size.height < 60) {
        contentRect.size.height = 60;
    }
    // 属性
    CGFloat titleH = 15;
    CGFloat titleY = contentRect.size.height - titleH - 5;
    CGFloat titleW = contentRect.size.width;
    
    return CGRectMake(0, titleY, titleW, titleH);
}

@end
